<template>
	<view class="box">
		<view class="jun-content">
			<view class="t_box_withdraw">
				<view class="t_header">
					<u-navbar title="提现" :titleStyle="{ color: '#fff' }" leftIconColor="#fff" leftIconSize="40"
						:autoBack="true" bgColor="rgba(255,255,255,0)">
					</u-navbar>
				</view>
				<view class="t_con_withdraw">
					<view class="one">
						<view class="one1">
							可提现金额（元)
						</view>
						<view class="one2">
							<em>￥</em>
							<text>{{user.money}}</text>
						</view>
					</view>
					<view class="two">
						<view class="two1">
							提现金额
						</view>
						<view class="two2 m-flex">
							<em>￥</em>
							<input type="text" v-model="form.money" placeholder="请输入提现金额">
							<label>手续费</label>
							<text>{{cashInfo.txsxf}}%</text>
						</view>
						<view class="two3">
							<text>单次提现金额最低</text>
							<text class="color-yellow">100元</text>
						</view>
						<div class="two3">折合<span>{{ sj() }}</span></div>
					</view>
					<view class="three2">
								<view :class="type == 1 ? 'xuanzhong':''" @click="type = 1">银行卡</view>
								<view :class="type == 2 ? 'xuanzhong':''" @click="type = 2">USDT</view>
						</view>
					
					<view class="item three" v-if="type == 1">
						<label for="paswd">银行卡号</label>
						<span v-if="bankOptions">{{bankOptions.name}}-{{bankOptions.account.substring(0,5)}} **** </span>
						<view @click="add(1)" v-if="!bankOptions" style="width: 25%;background-color: initial;border: 1px solid #ff0;color: #fff;border-radius: 10rpx;text-align: center;margin-left: 10rpx;padding: 10rpx 0;">立即添加</view>
						<!-- <ep-select label_key="banks" value_key="account" filterable keep-input v-model="select"
							:options="bankOptions" @change="change">
						</ep-select> -->
						<!-- <input type="text" id="card" :value="user.idcard | hiddenIdCard()" placeholder="请输入银行卡号"> -->
					</view>
					
					<view class="item three" v-if="type == 2">
						<label for="paswd">USDT</label>
						<span v-if="usdt">{{usdt.name}}-{{usdt.account.substring(0,5)}} ****</span>
							<view @click="add(2)" v-if="!usdt" style="width: 25%;background-color: initial;border: 1px solid #ff0;color: #fff;border-radius: 10rpx;text-align: center;margin-left: 10rpx;padding: 10rpx 0;">立即添加</view>
						<!-- <ep-select label_key="banks" value_key="account" filterable keep-input v-model="select"
							:options="bankOptions" @change="change">
						</ep-select> -->
						<!-- <input type="text" id="card" :value="user.idcard | hiddenIdCard()" placeholder="请输入银行卡号"> -->
					</view>
					<view class="item three">
						<label for="paswd">提现密码</label>
						<input type="password" id="paswd" v-model="form.pwd" placeholder="请输入提现密码">
					</view>
					<view class="model-row" style="margin-top: 30rpx;">
						<u-button @click="postCashs" color="#edd33a" :customStyle="{color:'#000',fontSize:'32rpx'}"
							text="确认提交"></u-button>
					</view>
					<view class="model cash-hint">
						提示:
						<view>1.提现限制：{{cashInfo.cash_min}}-{{cashInfo.cash_max}}</view>
						<view class="red">2.提现时间：{{cashInfo.cash_start}}-{{cashInfo.cash_end}}</view>
						<view>3.若忘记提现密码，请<text class="red">点击找回</text></view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		cash,
		cashs
	} from '@/config/api.js'
	export default {
		data() {
			return {
				type:1,
				money: '',
				truename: '',
				reason: '',
				cashInfo: {},
				user: {},
				form: {
					uid: uni.getStorageSync('uid'),
					bank: '',
					money: '',
					pwd: '',
					type:1
				},
				select: '',
				bankOptions: {},
				usdt:{}
			}
		},
		onLoad() {
			this.postCash()
		},
		methods: {
			add(type){
					if(type==1){
							this.$Router.push('/pages/mine/add_bank_card')
					}else{
						this.$Router.push('/pages/mine/add_usdt')
					}
			},
			sj(){
		let sxf=this.form.money*(this.cashInfo.txsxf/100);
	
		if(this.type==2){
			let sxf=(this.form.money/this.cashInfo.hlv)*(this.cashInfo.txsxf/100);
			if(this.form.money){
			
				return ((this.form.money/this.cashInfo.hlv)-sxf).toFixed(2)
				
				
			}else{
				return 0;
			}
	
		}else{
			if(this.form.money){
				return (parseFloat(this.form.money)-sxf).toFixed(2)
			}else{
				return '';
			}
			// return (this.jine-sxf).toFixed(2)
		}
		
	},
			// 账户信息
			postCash() {
				cash({
					params: {
						uid: uni.getStorageSync('uid')
					}
				}).then((res) => {
					console.log('res: ', res)
					this.cashInfo = res.data
					this.user = res.data.user
					this.bankOptions = res.data.bank
					this.usdt = res.data.usdt
					console.log('this.bankOptions: ', this.bankOptions)
					// res.data.bank.map((item) => {
					// 	item.banks = item.bank + ' ' + '****' + item.account.substring(item.account
					// 		.length - 4)
					// })
					this.form.bank = this.user.idcard
				}).catch(err => {
					console.log('err: ', err)
				})
			},
			// 充值
			postCashs() {
				if(this.form.pwd!=this.user.mwpassword2)return uni.$u.toast('提现密码不正确')
				this.form.type=this.type;
					
				if(this.type==1){
					this.form.bank=this.bankOptions?this.bankOptions.id:0
				}else{
					this.form.bank=this.usdt?this.usdt.id:0
				}
				cashs(this.form).then(res => {
					console.log('res: ', res)
					uni.$u.toast(res.info)
					setTimeout(() => {
						this.$Router.push('/pages/mine/cash_record')
					}, 2000)
					this.swiperList = res.data
				}).catch(err => {
					console.log('err: ', err)
				})
			},
			// 下拉选择
			change(e) {
				console.log('select = ', this.select)
				this.form.bank = this.select
			},
		}
	}
</script>

<style lang="scss" scoped>
.three2{
	width: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
	font-size: 24rpx;
	color: #fff;
	
	view{
		font-size: 34rpx;
		margin-right: 40rpx;
		// border-bottom: 2rpx solid transparent;
	}
	:last-child{
		margin-right: 0;
		margin-left: 40rpx;
	}
	.xuanzhong{
		border-bottom: 4rpx solid #edd33a;
		font-weight: 500;
	}
}
	.box {
		height: 100%;
		display: flex;
		flex-direction: column;

		.jun-content {
			height: 92%;
			width: 100%;
			display: flex;

			.t_box_withdraw {
				flex: 1;
				display: flex;
				flex-direction: column;
				background: url('../../static/images/dealBKG.png') no-repeat 50% -100px/745px;

				.t_con_withdraw {
					padding-top: 44px;

					.one {
						text-align: center;
						color: #fff;
						margin: 60rpx 0 100rpx;

						.one1 {
							font-size: 32rpx;
							font-weight: 500;
						}

						.one2 {
							font-size: 56rpx;
							font-weight: 700;

							em {
								font-size: 28rpx;
								vertical-align: baseline;
								font-style: normal;
							}

							text {
								display: inline-block;
							}
						}
					}

					.two {
						margin: 0 40rpx 80rpx;
						padding: 32rpx 22rpx;
						box-sizing: border-box;
						background: #262732;
						color: #fff;
						box-shadow: 0 14rpx 20rpx 2rpx #262732;
						border-radius: 10rpx;

						.two1 {
							display: block;
							margin-bottom: 20rpx;

						}

						.two2 {
							em {
								font-size: 48rpx;
								margin-right: 20rpx;
								font-style: normal;
							}

							input {
								background: transparent;
								color: #fff;
								font-size: 28rpx;
							}
						}

						.two3 {
							margin-top: 40rpx;
							font-size: 26rpx;
							font-weight: 400;
							color: #999;

							.color-yellow {
								color: #edd33a;
							}
						}
					}

					.three {
						// display: flex;
						// flex-direction: row;
						// margin: 0 40rpx;
						// height: 94rpx;
						// font-size: 28rpx;
						// border-bottom: 1px solid #333;
						// position: relative;
					}

					.item {
						margin: 0 40rpx;
						height: 94rpx;
						font-size: 28rpx;
						border-bottom: 1px solid #333;
						position: relative;
						display: flex;
						flex-direction: row;
						align-items: center;

						label {
							display: inline-block;
							margin-left: 28rpx;
							color: #fff;
							width: 186rpx;
							font-size: 28rpx;
							height: 100%;
							line-height: 94rpx;
							float: left;
						}

						input {
							background: transparent;
							color: #333;
							margin-top: 10rpx;
							height: 74rpx;
							font-size: 28rpx;
							text-indent: 52rpx;
							// background-color: #111723;
							border: none;
							outline: none;
							color: #fff;
						}
					}
				}
			}
		}
	}

	.cash-hint {
		.red {
			color: red;
		}
	}
</style>
